<?php

    class Application_Validadores_ConfirmarContrasenha extends Zend_Validate_Abstract
    {
        
        const NOT_MATCH = 'notMatch';

        protected $_messageTemplates = array(
            self::NOT_MATCH => 'Confirmación y contraseña deben ser iguales'
        );
        
        /**
        * @var array
        */
        protected $_messageVariables = array(
            'clave' => '_clave'
        );

        /**
        * Name of the field as it appear in the $context array.
        *
        * @var string
        */
        protected $_clave;
        
        /**
        * Sets validator options
        *
        * @param  string $fieldName
        * @param  string $fieldTitle
        * @return void
        */
        public function __construct($clave = null) {
            $this->setClave($clave);
        }

        /**
        * Returns the field name.
        *
        * @return string
        */
        public function getClave() {
            return $this->_clave;
        }

        /**
        * Sets the field name.
        *
        * @param  string $fieldName
        * @return Zend_Validate_IdenticalField Provides a fluent interface
        */
        public function setClave($clave) {
            $this->_clave = $clave;
            return $this;
        }
        
        public function isValid($value, $context = null)
        {
            $value = (string) $value;
            $this->_setValue($value);
            $comp_array = $this->getClave();
            $confirmar = $comp_array["clave"];
            

            if (is_array($context)) {
                if (isset($context[$confirmar])
                    && ($value == $context[$confirmar]))
                {
                    return true;
                }
            } elseif (is_string($context) && ($value == $context)) {
                return true;
            }

            $this->_error(self::NOT_MATCH);
            return false;
        }
    }

?>
